package main.strategy;
import exception.LoginErrorException;
import main.robClass;
import robber.impl.PERobber;

import user.IUser;
import user.impl.OOUser;

import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class StartGetLoginCookie implements RobStrategy {
    @Override
    public void execute(IUser user)  {

        ScheduledExecutorService pool = Executors.newScheduledThreadPool(30);
        pool.scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                robClass.logger.info(Thread.currentThread().getId()+" # "+user.getUsername()+" # "+user.getStudentName()+" # 登录多线程冲冲冲!");
                try {
                    try {
                        user.login();
                    } catch (Exception e) { //处理登陆异常状态
                        e.printStackTrace();
                    }
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, 0, 1, TimeUnit.SECONDS);
    }

}
